package com.example.workbench.controller;

import com.example.workbench.common.api.CommonResult;
import com.example.workbench.common.command.AddLineCommand;
import com.example.workbench.common.command.DelByIdCommand;
import com.example.workbench.common.command.UpdateLineCommand;
import com.example.workbench.common.command.UpdateSortCommand;
import com.example.workbench.entity.DbTaskLine;
import com.example.workbench.service.IDbTaskLineService;
import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.json.JsonObject;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2024-08-03
 */
@RestController
@RequestMapping("/line")
public class DbTaskLineController {
    @Autowired
    private IDbTaskLineService taskLineService;

    @PostMapping("/add")
    public CommonResult addLine(@RequestBody AddLineCommand command) {
        if (StringUtils.isEmpty(String.valueOf(command.getTaskId()))||
                StringUtils.isEmpty(command.getLineName())) {
            return CommonResult.failed("参数不能为空");
        }
        return taskLineService.addLine(command);
    }
    @PostMapping("/del")
    public CommonResult delLine(@RequestBody DelByIdCommand command) {
        if (StringUtils.isEmpty(String.valueOf(command.getId()))){
            return CommonResult.failed("参数不能为空");
        }
        return taskLineService.delLine(command.getId());
    }

    @PostMapping("/update")
    public CommonResult update(@RequestBody UpdateLineCommand command) {
        if (StringUtils.isEmpty(String.valueOf(command.getId()))||
        StringUtils.isEmpty(command.getLineName())) {
            return CommonResult.failed("参数不能为空");
        }
        return taskLineService.updateLine(command);
    }
    @PostMapping("/query")
    public CommonResult<List<DbTaskLine>> queryLine(@RequestBody DelByIdCommand command) {
        if (StringUtils.isEmpty(String.valueOf(command.getId()))){
            return CommonResult.failed("参数不能为空");
        }
        List<DbTaskLine> list = taskLineService.queryLine(command.getId());
        return CommonResult.success(list);
    }

    @PostMapping("updateSort")
    public CommonResult<String> updateSort(@RequestBody UpdateSortCommand command) {
        return taskLineService.updateSort(command);
    }
}
